package com.zfjt.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zfjt.entity.UserBean;
import com.zfjt.service.UserService;

@Controller
public class UserWebController
{

	@Autowired
	private UserService userService;

	// 用户登陆
	@RequestMapping(value = "userLogin", method = RequestMethod.POST)
	public String userLogin(UserBean user)
	{
		UserBean bean = userService.selectByName(user);
		if (bean != null)
		{
			return "index";
		} else
		{
			return "405";
		}
	}

	// 用户管理界面
	@RequestMapping("userManager")
	public String userList()
	{
		return "user/userManager";
	}

	// 修改用户
	@RequestMapping("updateUser/{userId}")
	@ResponseBody
	public Integer updateUser(@PathVariable String userId, UserBean user)
	{
		user.setUserId(userId);
		return userService.updateByPrimaryKeySelective(user);
	}

	// 得到用户数据集
	@RequestMapping("userData")
	@ResponseBody
	public List<UserBean> userData()
	{
		List<UserBean> userBeans = userService.selectAll();
		return userBeans;
	}
}
